<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    function number(arr) {
        let newarr = [];
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] < 9 && arr[i] >= 0) {
                arr.push(arr[i])
            }
        }
        let str = newarr.sort((a, b) => a - b)
        let res = []
        for (let i = 0; i < str.length; i++) {
            if (res.indexOf(str[i]) == -1) {
                res.push(str[i])
            }
        }
        if (res.length < 2) {
            return -1;
        } else {
            return res[1]
        }
    }
    console.log(number([2,3,4,5,6,7]));
</script>